package com.social.instadownloader.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.social.instadownloader.R;
import com.social.instadownloader.screen.DownloadScreen;
import com.social.instadownloader.screen.HistoryScreen;
import com.social.instadownloader.screen.HowItWorkScreen;
import com.social.instadownloader.util.AndroidVersionUtils;

public class TabFragmentActivity extends FragmentActivity{

	/** The m tab host. */
	private FragmentTabHost mTabHost;
	
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.bottom_tabhost);
		initTab();
	}
	
	/**
	 * Inits the tab.
	 */
	@SuppressLint("NewApi")
	private void initTab() {
		mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
		if(AndroidVersionUtils.isHoneycombOrHigher()){
			mTabHost.getTabWidget().setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
		}else{
			mTabHost.getTabWidget().setDividerDrawable(null);
		}
		
		mTabHost.addTab(mTabHost.newTabSpec("HowItWork").setIndicator(getIndicator("How It Work", R.drawable.ic_bookmark_tab)),
				HowItWorkScreen.class, null);
		mTabHost.addTab(mTabHost.newTabSpec("Download").setIndicator(getIndicator("Download", R.drawable.ic_download_tab)), 
				DownloadScreen.class, null);
		mTabHost.addTab(mTabHost.newTabSpec("History").setIndicator(getIndicator("Downloaded", R.drawable.ic_download_tab)),
				HistoryScreen.class, null);
//		mTabHost.getTabWidget().setStripEnabled(false);
		// setContentView(mTabHost);
	}
	
	public void changeCurrentTab(int index){
		mTabHost.setCurrentTab(index);
	}
	/**
	 * Gets the indicator.
	 *
	 * @param text the text
	 * @param drawableId the drawable id
	 * @return the indicator
	 */
	public View getIndicator(String text,int drawableId){
		View v = LayoutInflater.from(this).inflate(R.layout.tab_indicator, null);
		if(text!=null){
			((TextView)v.findViewById(R.id.tvTitle)).setText(text);
		}
		if(drawableId!=0){
			((ImageView)v.findViewById(R.id.imgTabIcon)).setImageResource(drawableId);
		}
		return v;
	}
	
}
